package com.example.seckill.controller;


// import com.alibaba.csp.sentinel.annotation.SentinelResource;
// import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.seckill.entity.dto.SeckillDto;
import com.example.seckill.service.TSeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 丁昌江
 * @since 2021-08-10
 */
@RestController
@RequestMapping("/seckill")
public class TSeckillGoodsController {

    @Resource
    private TSeckillGoodsService seckillGoodsService;

    /**
     * redisson做分布式锁的秒杀接口
     * @param seckillDto seckillDto
     */
    @PostMapping("goods")
    // @SentinelResource(value = "seckill",blockHandler = "seckillHandler")
    public String goods(@RequestBody SeckillDto seckillDto) {
        seckillGoodsService.seckill(seckillDto);
        return "下单成功，请尽快付款";
    }

    // public static String seckillHandler(SeckillDto seckillDto, BlockException e) {
    //     return "系统繁忙，请稍后重试";
    // }


    /**
     * redisson 做分布式锁初始化，redis 内存扣减的秒杀接口
     * @param seckillDto seckillDto
     */
    @PostMapping("redisStock")
    public String seckillWithRedisStock(@RequestBody SeckillDto seckillDto) {
        seckillGoodsService.seckillWithRedisStock(seckillDto);
        return "下单成功，请尽快付款";
    }
}
